﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Reticulum
{
    public partial class AllFlie : Form
    {
        public AllFlie()
        {
            InitializeComponent();
        }

        private void AllFlie_Load(object sender, EventArgs e)
        {
            
            string sql = "select u.UserName,f.FlieName,f.FlieLength,f.FlieRoute,f.FlieSuffix,f.FlieGetTime,f.original_File_name " +
                "from FlieInfo f, Users u where f.UserID = u.UserID";

            DataSet ds = DBHelps.Adapter(sql);

            dataGridView1.AutoGenerateColumns = false;

            dataGridView1.DataSource = ds.Tables[0];
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            AllFlie_Load(sender, e);//刷新数据
        }


        private void toolStripButton1_Click(object sender, EventArgs e)//按用户
        {
            
            int index = toolStripTextBox1.Text.IndexOf("*.");
            if (index!=-1)
            {
                string sql = "select u.UserName,f.FlieName,f.FlieLength,f.FlieRoute,f.FlieSuffix,f.FlieGetTime,f.original_File_name from FlieInfo f, Users u where f.UserID = u.UserID";

                DataSet ds = DBHelps.Adapter(sql);
                //获取输入的关键字
                string FlieName = toolStripTextBox1.Text;
                //创建dataview对象
                DataView dv = ds.Tables[0].DefaultView;
                //模糊查询
                dv.RowFilter = string.Format("FlieSuffix like '%{0}%'", FlieName);
                //设置DataView的数据源
                this.dataGridView1.DataSource = dv;
            }
            else
            {
                string sql = "select u.UserName,f.FlieName,f.FlieLength,f.FlieRoute,f.FlieSuffix,f.FlieGetTime,f.original_File_name " +
                "from FlieInfo f, Users u where f.UserID = u.UserID";

                DataSet ds = DBHelps.Adapter(sql);
                //获取输入的关键字
                string FlieName = toolStripTextBox1.Text;
                //创建dataview对象
                DataView dv = ds.Tables[0].DefaultView;
                //模糊查询
                dv.RowFilter = string.Format("FlieName like '%{0}%'", FlieName);
                //设置DataView的数据源
                this.dataGridView1.DataSource = dv;
            }
        }

        private void toolStripTextBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //在输入用户名框中键盘回车可以进行登陆
            if (e.KeyChar == (char)13)//ASCII 13为回车的码
            {
                toolStripButton1_Click(sender, e);//使用登陆按钮方法
            }
        }
    }
}
